/**
*****************************************************************************************
*     Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
*****************************************************************************************
* @file     fast_prov_service.h
* @brief    Head file for fast provisione service
* @details
* @author   hector_huang
* @date     2020-07-15
* @version  v1.0
* *************************************************************************************
*/

#ifndef _FAST_PROV_SERVICE_H_
#define _FAST_PROV_SERVICE_H_

#include "platform_types.h"

BEGIN_DECLS

/**
 * @addtogroup Fast_Prov
 * @{
 */

/**
 * @defgroup Fast_Prov_Exported_Macros Exported Macros
 * @{
 */

/** characteristic uuid */
#define FAST_PROV_DATA_IN_UUID             0xFFE4
#define FAST_PROV_DATA_OUT_UUID            0xFFE5

/* opcode */
#define OPCODE_FAST_PROV_ENABLE            0x01
#define OPCODE_UNPROV_DEV                  0x02
#define OPCODE_DEV_SET_ADDR_KEY            0x03
#define OPCODE_DEV_PROV_SUCCESS            0x04
#define OPCODE_DEV_SET_NET_KEY             0x05
#define OPCODE_DEV_SET_APP_KEY             0x06
#define OPCODE_DEV_SET_IV_INDEX            0x07
/** @} */

typedef struct
{
    uint8_t opcode;
    bool enable;
} _PACKED_ fast_prov_service_mode_enable_t;

typedef struct
{
    uint8_t opcode;
    uint8_t mac_addr[6];
    uint8_t elem_num;
    uint32_t pid;
} _PACKED_ fast_prov_service_unprov_dev_t;

typedef struct
{
    uint8_t opcode;
    uint16_t unicast_addr;
    uint8_t dev_key[16];
} _PACKED_ fast_prov_service_set_dev_addr_key_t;

typedef struct
{
    uint8_t opcode;
    uint8_t mac_addr[6];
} _PACKED_ fast_prov_service_prov_success_t;

typedef struct
{
    uint8_t opcode;
    uint8_t key_refresh_flag;
    uint16_t net_key_index;
    uint8_t net_key[16];
} _PACKED_ fast_prov_service_set_net_key_t;

typedef struct
{
    uint8_t opcode;
    uint16_t app_key_index;
    uint8_t app_key[16];
} _PACKED_ fast_prov_service_set_app_key_t;

typedef struct
{
    uint8_t opcode;
    uint8_t iv_update_flag;
    uint32_t iv_index;
} _PACKED_ fast_prov_service_set_iv_index_t;

/**
 * @defgroup Data_Trans_Exported_Types Exported Types
 * @{
 */

/** 128bit UUID of data transmission service */
extern const uint8_t FAST_PROV_SERVICE_UUID[16];

/** @} */

END_DECLS

#endif /** _FAST_PROV_SERVICE_H_ */

